﻿using System;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service.Model
{
    /// <remarks/>
    [XmlType(AnonymousType = true)]
    [XmlRootAttribute(ElementName = "user", Namespace = "", IsNullable = false)]
    [ZenRestRequest("me", "me")]
    public partial class User : IUser
    {
        private IStory[] _stories;

        private string _bio;

        /// <remarks/>
        [XmlElement(ElementName = "bio")]
        public string Bio
        {
            get { return _bio; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _bio = value;
                else
                    _bio = null;
            }
        }

        /// <remarks/>
        [XmlElement(ElementName = "createTime")]
        public string CreateTimeXmlElement
        {
            get
            {
                if (this.CreateTime == null)
                    return null;

                return this.CreateTime.Value.ToString("yyyy-MM-ddThh:mm:ss");
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                    this.CreateTime = null;
                else
                    this.CreateTime = DateTime.Parse(value);
            }
        }

        [XmlIgnore]
        public DateTime? CreateTime { get; set; }

        private string _email;

        /// <remarks/>
        [XmlElement(ElementName = "email")]
        public string Email
        {
            get { return _email; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _email = value;
                else
                    _email = null;
            }
        }

        /// <remarks/>
        [XmlElement(ElementName = "id")]
        public int Id { get; set; }

        private string _name;

        /// <remarks/>
        [XmlElement(ElementName = "name")]
        public string Name
        {
            get { return _name; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _name = value;
                else
                    _name = null;
            }
        }

        private string _userName;

        /// <remarks/>
        [XmlElement(ElementName = "userName")]
        public string UserName
        {
            get { return _userName; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _userName = value;
                else
                    _userName = null;
            }
        }

        [XmlArrayItemAttribute("story", IsNullable = false)]
        [XmlArray(ElementName = "stories")]
        public Story[] StoriesXmlElement
        {
            get { return _stories as Story[]; }
            set { _stories = value; }
        }

        [XmlIgnore]
        public ReadOnlyCollection<IStory> Stories
        {
            get { return new ReadOnlyCollection<IStory>(_stories); }
        }

    }
}